import matplotlib.pyplot as plt

class ChartGenerationUtils:

    @staticmethod
    # 生成饼图
    def create_piechart_image(image_path, data):
        # 支持中文
        plt.rcParams['font.sans-serif'] = ['SimHei']
        plt.rcParams['axes.unicode_minus'] = False
        plt.figure(figsize=(10, 6))
        plt.pie(data.get("values"), labels=data.get("labels"), autopct='%1.1f%%', startangle=140)
        plt.title(data.get("title"))
        plt.savefig(image_path, dpi=300, bbox_inches='tight')
        plt.close()

    @staticmethod
    # 生成柱状图
    def create_barchart_image(image_path, data):
        # 支持中文
        plt.rcParams['font.sans-serif'] = ['SimHei']
        plt.rcParams['axes.unicode_minus'] = False
        plt.figure(figsize=(10, 6))
        plt.bar(data.get("labels"),data.get("values"), color='skyblue')
        plt.title(data.get("title"))
        plt.xlabel(data.get("xlabel"))
        plt.ylabel(data.get("ylabel"))
        plt.tight_layout()
        plt.savefig(image_path, dpi=300, bbox_inches='tight')
        plt.close()